import React, { Component } from 'react'
import Child from './child'

export default class parent extends Component {
    state={
        hasError:''
    }
    static getDerivedStateFromError(error){
        //错误边界在线上环境，生产环境不起效且只处理render的错误
    return {hasError:error}
    }
    componentDidCatch(){
        //错误时调用
    }
    render() {
        return (
            <div>
                <h2>parent</h2>
                {this.state.hasError?<h2>...</h2>:<Child/>}
                
            </div>
        )
    }
}
